/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javase2203 - T13
 * <p>Powered by webrx On 2022-08-09 14:35:01
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T13 {
    final Object lock = new Object();
    void m() {
        System.out.println(Thread.currentThread().getName() + "启动等待...");
        try {
            synchronized (lock) {
                lock.wait();//进入阻塞状态，
            }
            System.out.println(Thread.currentThread().getName() + "被唤醒了...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        var t = new T13();
        for (int i = 0; i < 5; i++) new Thread(t::m, "T" + i).start();

        try {
            TimeUnit.SECONDS.sleep(5);
            synchronized (t.lock) {
                //t.lock.notify();
                t.lock.notifyAll();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
